﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace Tomahawk.Runtime.Canvas.Sprite
{
    /// <summary>
    /// An UITextSprite is a text rendered to the UI.
    /// As it will be usually rendered between image components, 
    /// it will use the inmediate mode for best perf.
    /// </summary>
    public class UITextSprite : Sprite
    {
        /// <summary>
        /// Holds the font asset
        /// </summary>
        string fontAsset = "";

        private SpriteFont font;

        private Vector2 renderPosition;

        /// <summary>
        /// Stores the text as the user entered (unlocalized)
        /// </summary>
        private string text;

        /// <summary>
        /// Constructor
        /// </summary>
        public UITextSprite(string fontAsset, string text)
        {
            this.fontAsset = fontAsset;
            this.text = text;
        }

        /// <summary>
        /// Load contents
        /// </summary>
        protected override bool OnLoad(GraphicsDevice graphics, ContentManager contentManager)
        {
            //load the font
            font = contentManager.Load<SpriteFont>(this.fontAsset);

            //
            return true;
        }

        /// <summary>
        /// Draw the primitive, must be called with an already opened and configured SpriteBatch
        /// </summary>
        public override void Render(SpriteBatch spriteBatch)
        {
            //discard width and height from destinationRectangle
            this.renderPosition.X = this.DestinationRectangle.X;
            this.renderPosition.Y = this.DestinationRectangle.Y;
            spriteBatch.DrawString(this.font, this.text, this.renderPosition, this.Color);
        }



    }

}
